Hello and welcome back to the call.
So now we are coming to the core methods of my old course.
So when it comes to large scale and numerical operations none pay as much faster than the pace and standard
library.
Because they are we can use spectre raised element y's operations and we do not need any follow up size
statements and so on.
And in this sense though we can also save many lines of code with an empire in Python we can measure
the time our machine needs for the execution of code.
So with the magic function time it so it's called magic because it starts as a percentage sign.
So there are many so-called magic functions and time it runs the code multiple times and returns as
the ever it's execution time.
So but now let's first impact an umpire and then reset the size of our lists and our race.
First of all to three so we only have three elements and then we create an umpire array with three elements.
So the length is three.
So we have an array that's 0 1 and 2.
And also we create a list with the range function and three elements as you can see now here we have
our array and our list l.
And now we measure the time our machine needs to add to each element in our array and the integer to
so it's 660 nanoseconds.
And the same we are doing now for the list.
So we have a list comprehension.
So for each element in our list there are only three elements we add to let's also measured the time
here.
Here we have two hundred seventy six nanoseconds.
So you can see in the very small scale operation num pi is slower here than than the python standard
library and we can also try other operations like multiplication.
So we multiply each element of our array by two
so we get six hundred fifty nine nanoseconds and we do the same four for the list elements multiplying
by two
and also here two hundred seventy nanoseconds at least at a small scale with only three elements num
pi is slower let's go onto squaring our elements and let's see the average time for the man pi package.
So it's five hundred fifty seven nanoseconds and we do the same with the list comprehension
so now obviously here with the operations squaring num pi is faster than than the python standard library.
So before here with additional multiplication non PI was two times slower than the python standard library
so in the end it also depends which operation you have under.
Let's also try to get to the square root of the number package
eight hundred seventy six nanoseconds and let's do the same.
This list comprehension
now again here the pace and standard library is faster.
So it depends on the operation of the type of the operation.
All right so but it seems very a very small scale that.
Yeah.
That's not really an advantage of the number I package.
But um let's increase our size of elements from three to let's say 1 million.
So we have from our array 1 million elements.
And also on our list and let's read from the whole thing.
So let's begin with Ed..
So now we have two point two three milliseconds for the month.
Hi Ed..
Let's see what we get with the list comprehension.
Now we get your ninety two point eight milliseconds so Nampa here was about the hour forty or forty
five times faster than Python standard library.
And let's also try the multiplication with one million elements.
So now I'm pi needs on average two points with six milliseconds.
And let's try the python standard library
also here ninety two point eight milliseconds so about forty forty five times slower than empire and
let's go onto a squaring
two points three eight milliseconds for the number pi package.
And the list comprehension
362 milliseconds num pi is about 250 times faster than the python standard library.
And last but not least the square root
nine point four one milliseconds and this comprehension 217 milliseconds now pays about twenty times
faster than the python standard library so we have seen that.
Yeah.
I'm pi is when it comes to very large scale operations with uh thousands or millions of elements.
The number is really much faster.
So on average about 50 to a 100 times faster than the python standard library.
And it also depends on the type of operations.
All right so this is it for the time being and in the next session we will have a small case study where
we also have a look at the performance between num pi enterprise and standard library so hope to see
you there by.